package com.example.tellwin.mine.presenter;

import com.example.tellwin.AppHelper;
import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.mine.bean.ExpenseRecordContentBean;
import com.example.tellwin.mine.bean.ShareContentBean;
import com.example.tellwin.mine.bean.UserContentBean;
import com.example.tellwin.mine.contract.ShareRecordContract;
import com.example.tellwin.mine.contract.WalletContract;
import com.example.tellwin.utils.ToastUtil;

import javax.inject.Inject;

/**
 * @author : LinZePeng
 * @date : 2020/12/1
 * @Describe ：
 **/
public class ShareRecordPresenter extends RxPresenter<ShareRecordContract.View> implements ShareRecordContract.Presenter<ShareRecordContract.View> {

    private TwjfApi mApi;

    private int pages;
    private int pageNum;
    private final int pageSize = 10;
    private boolean isNotMore = true;

    @Inject
    public ShareRecordPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void getShareRecord() {
        pageNum = 1;
        pages = 0;
        isNotMore = false;
        mApi.shareList(pageNum + "", pageSize + "", new SimpleCallback<ShareContentBean>(mView) {
            @Override
            public void onSuccess(ShareContentBean shareContentBean) {
                pageNum = shareContentBean.getPageNum();
                pages = shareContentBean.getPages();
                if (shareContentBean.getShareList() == null || shareContentBean.getShareList().size() == 0) {
                    //   ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                    isNotMore = true;
                    return;
                }
                if(shareContentBean.getShareList().size()<10){
                    isNotMore = true;
                }
                mView.shareRecordResult(shareContentBean.getShareList());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void loadMore() {
        if (isNotMore) {
            return;
        }
        if (pages != 0 && pageNum == pages) {
          //  ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
            isNotMore = true;
            return;
        }
        pageNum++;
        mApi.shareList(pageNum + "", pageSize + "", new SimpleCallback<ShareContentBean>(mView) {
            @Override
            public void onSuccess(ShareContentBean shareContentBean) {
                pageNum = shareContentBean.getPageNum();
                pages = shareContentBean.getPages();
                if (shareContentBean.getShareList() == null || shareContentBean.getShareList().size() == 0) {
                    ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                    isNotMore = true;
                    return;
                }
                mView.loadMoreResult(shareContentBean.getShareList());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

}
